package com.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.mapper.NoticeMapper;
import com.demo.pojo.Notice;
import com.demo.pojo.ResultVO;
import com.demo.service.NoticeService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper,Notice> implements NoticeService {

    @Override
    public ResultVO<List<Notice>> getNoticeList(Integer readStatus) {
        List<Notice> list = this.list();
        return ResultVO.success(list);
    }

    @Override
    public Notice getNoticeDetail(Long id) {
        // 根据ID查询公告详情
        return baseMapper.selectById(id);
    }

    @Override
    public void addNotice(Notice notice) {
        notice.setPublishTime(new Date()); // 设置发布时间为当前时间
        notice.setReadStatus(0); // 默认为未读
        this.save(notice);
    }

    @Override
    public void markAsRead(@RequestBody Notice notice) {
        notice.setReadStatus(1); // 将阅读状态设为“已读”
        this.save(notice);
    }
}